using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace StupidSpaceThing
{
	internal class CounterGuide : Guide
	{
		private double time;
		private string text;
		private double remaining;
		private SpriteFont font;

		public CounterGuide(double time, string text, SpriteFont font, GuideCallback callback) : base(0, callback) {
			this.time = time;
			this.text = text;
			this.font = font;
		}

		public override void Update(RealGameTime gameTime) {
			double elapsed = gameTime.TotalRealGameTime.TotalMilliseconds - StartTime;
			remaining = time - elapsed;
			if( remaining < 0 ) {
				remaining = 0;
				if( Callback != null ) {
					Callback();
				}
				End();
			}
		}

		public override void Draw(SpriteBatch spriteBatch) {
#if XBOX
			int leftOffset = 50;
			int topOffset = 30;
#else
			int leftOffset = 10;
			int topOffset = 10;
#endif
			int totalseconds = (int)(remaining / 1000);
			int minutes = totalseconds / 60;
			int seconds = totalseconds % 60;
			spriteBatch.DrawString(font, text + " " + minutes + ":" + seconds.ToString().PadLeft(2, '0'), new Vector2(leftOffset,topOffset), GetColor(Color.White));
			base.Draw(spriteBatch);
		}
	}
}
